Page
---
title: "App sample"
author: "Jorge Velez"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
---
Visualizations 1 {data-icon="fa-signal"}
=====================================
Page
```{r, include=FALSE}
library(leaflet)
library(stringr)
library(tibble)
library(tidyverse)
library(dplyr)
library(plyr)
library(leaflet.extras)
library(scales)
library(sp)
# Load library
library('sf')
library(ggplot2)
library(plotly)
library(plyr)
library(flexdashboard)
# Make some noisily increasing data
set.seed(955)
dat <- data.frame(cond = rep(c("A", "B"), each=10),
xvar = 1:20 + rnorm(20,sd=3),
yvar = 1:20 + rnorm(20,sd=3))
# Load shapefile
col <- read_sf('C:/Users/velez/Desktop/Shiny R/leaflet/mychapter/Tasa_de_repitencia_en_el_sector_oficial_desde_transicion_hasta_grado_once.shp')
summary(col)
# Print the slot names of `shp`
slotNames(col)
# Glimpse the data slot of shp
glimpse(col)
# Print the class of `shp`
class(col)
# map the polygons in shp
col %>%
leaflet() %>%
addTiles() %>%
addPolygons()
# summarize the mean income variable
summary(col$BasicaSecu)
####Map
nc_pal <- colorNumeric("YlGn", domain = NULL)
col_map <-
leaflet(col) %>%
addTiles() %>%
addPolygons(weight = 1, fillOpacity = 1,
color = ~nc_pal(BasicaSecu),
label = ~paste0(Departamen, ": ", BasicaSecu),
highlight = highlightOptions(weight = 3,
color = "red",
bringToFront = TRUE)) %>%
addLegend(pal = nc_pal, values = ~BasicaSecu, opacity = 0.7, title = "Repeat rate in secondary Education",
position = "topright") %>%
setView(lat = 4.624335, lng = -74.063644, zoom = 4)
```
### Map 1
-----------------------------------------------------------------------
### Geometry smooth with Loess Smoothed Fit
```{r}
p <- ggplot(dat, aes(x=xvar, y=yvar)) +
geom_point(shape=1) + # Use hollow circles
geom_smooth() # Add a loess smoothed fit curve with confidence region
ggplotly(p)
```
```
### Colombian map: Children's Repeat rate (Secondary)
```{r, echo=FALSE, fig.dim = c(6, 4)}
col_map
```
Visualisations 2
=======================================================================
Row
-----------------------------------------------------------------------
### stat_density Example
```{r}
dfGamma = data.frame(nu75 = rgamma(100, 0.75),
nu1 = rgamma(100, 1),
nu2 = rgamma(100, 2))
dfGamma = stack(dfGamma)
p <- ggplot(dfGamma, aes(x = values)) +
stat_density(aes(group = ind, color = ind),position="identity",geom="line")
ggplotly(p)
```
### A scatter
```{r}
library(plotly)
library(gapminder)
p <- gapminder %>%
plot_ly(
x = ~gdpPercap,
y = ~lifeExp,
size = ~pop,
color = ~continent,
frame = ~year,
text = ~country,
hoverinfo = "text",
type = 'scatter',
mode = 'markers'
) %>%
layout(
xaxis = list(
type = "log"
)
)
p
```
Row
-----------------------------------------------------------------------
### A geom. density
```{r}
dd<-data.frame(matrix(rnorm(144, mean=2, sd=2),72,2),c(rep("A",24),rep("B",24),rep("C",24)))
colnames(dd) <- c("x_value", "Predicted_value", "State_CD")
dd <- data.frame(
predicted = rnorm(72, mean = 2, sd = 2),
state = rep(c("A", "B", "C"), each = 24)
)
grid <- with(dd, seq(min(predicted), max(predicted), length = 100))
normaldens <- ddply(dd, "state", function(df) {
data.frame(
predicted = grid,
density = dnorm(grid, mean(df$predicted), sd(df$predicted))
)
})
p <- ggplot(dd, aes(predicted)) +
geom_density() +
geom_line(aes(y = density), data = normaldens, colour = "red") +
facet_wrap(~ state)
ggplotly(p)
```
### A scatterplo sample
```{r}
# Source: https://github.com/dgrtwo/gganimate
# install.packages("cowplot") # a gganimate dependency
# devtools::install_github("dgrtwo/gganimate")
library(ggplot2)
library(gganimate)
library(gapminder)
theme_set(theme_bw()) # pre-set the bw theme.
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
geom_point() +
transition_time(year) +
ggtitle("Year: {frame_time}") +
transition_time(year) +
ease_aes("linear") +
enter_fade() +
exit_fade()
# animate
animate(p)
```
Tables {data-icon="fa-table"}
=====================================
### Table 1
```{r}
```
### Table 2
```{r}
```